// a simple directional light source

#include <math.h>

#include "../include/point_light.h"

// specified by a direction and a colour

PointlLight::PointlLight(Vertex &p, Colour &i) {
	position.x = p.x;
	position.y = p.y;
	position.z = p.z;
	position.w = p.w;
	intensity.set(i.getRed(), i.getGreen(), i.getBlue(), i.getAlpha());
}

// provide the intensity and direction from which light arrives at given vertex

void PointlLight::getLightProperties(Vertex &pos, Vector *ldir, Colour *i) {
	Vector dir = position - pos;

	double length = sqrt(dir.x * dir.x + dir.y * dir.y + dir.z * dir.z);
	dir.x /= length; dir.y /= length; dir.z /= length;

	ldir->x = dir.x;
	ldir->y = dir.y;
	ldir->z = dir.z;

	double distance = pos.distance(position);
	double dissqu = distance*distance;
	i->set(intensity.getRed()/dissqu, intensity.getGreen()/dissqu, intensity.getBlue()/dissqu,
			intensity.getAlpha());
}

Vertex PointlLight::getPosition(Vertex &pos)
{
	Vertex returnVar;
//	returnVar.set(-position.x,-position.y,-position.z,position.w);
	returnVar = position;
	return returnVar;
}
